home *** CD-ROM | disk | FTP | other *** search
- Path: seagull.rtd.com!collins
- From: collins@RTD.COM (Ronald Collins)
- Newsgroups: comp.lang.c
- Subject: Re: Standard question - pointer initialization
- Date: 13 Mar 1996 20:48:52 GMT
- Organization: RTD Internet Access
- Message-ID: <4i7cbl$5da@baygull.rtd.com>
- References: <4hk9un$906@hammer.msfc.nasa.gov> <4hl6rr$nde@news.xs4all.nl> <313E6028.1C19@ix.netcom.com> <4hnpsl$g8c@hacgate2.hac.com> <4hq9hsINN998@keats.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: seagull.rtd.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) wrote:
- : In article <4hnpsl$g8c@hacgate2.hac.com>,
- : Ron Collins <collins@thor.tu.hac.com> wrote:
- : >Norman Bullen (nbullen@ix.netcom.com) wrote:
- : >[snip]
- : >
- : >: And there is no point in initializing a pointer when its declared if you
- : >: don't know at that point what an appropriate value might be. Use of a
- : >: pointer that has been initialized with an inappropriate value can be just
- : >: as bad for the program as using an uninitialize pointer.
- : >
- : >The popular convention (when initializing pointers) is to set them to
- : >NULL. This is the appropriate value to use when checking for invalid
- : >pointer usage.
-
- : This is not a popular convention, but something that is demanded by the
- : language standard. A static uninitialized pointer shall take on a value that
- : corresponds to a null pointer, whatever that bit pattern is.
-
- I know this is the requirement for static variables. But I beleive
- (I could be wrong) that the original question referred to automatic
- variables, for which the standard imposes no such requirement.
-
- [snip]
-
- : By the way, null pointers are not for checking for incorrect pointer usage. It
- : is obviously legal and useful for a pointer to have a null value. Such a value
- : is guaranteed to always be distinct from a pointer which references an actual
- : object.
- : --
-
- A NULL pointer is the _one_ value guaranteed to be illegal to dereference..
- Although not it's primary purpose, it seems ready-made to trap for
- debugging purposes.
-
- -- collins --
-
-